import { ref } from 'vue';
import { defineStore } from 'pinia';
import type { ITheme } from '@/apis/type';
// 加密缓存
// import { st } from './index';

export const useThemeStore = defineStore(
  'themeStore',
  () => {
    const theme: Ref<ITheme> = ref('light');
    const getTheme = (): ITheme => {
      return theme.value;
    };
    const setTheme = (val: ITheme) => {
      theme.value = val;
      editBodyClass();
    };
    const editBodyClass = () => {
      document.getElementsByTagName('html')[0].className = theme.value;
    };
    return { theme, getTheme, setTheme, editBodyClass };
  },
  { persist: true }
);
